/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('iqs', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AISearchQuery {
  card?: string(name='card'),
  cardQuery?: string(name='cardQuery'),
  page?: int32(name='page'),
  query?: string(name='query'),
  searchEngine?: string(name='searchEngine'),
  searchPlan?: string(name='searchPlan'),
  sessionId?: string(name='sessionId'),
  timeRange?: string(name='timeRange'),
}

model GenericSearchResult {
  pageItems?: [
    ScorePageItem
  ](name='pageItems'),
  queryContext?: QueryContext(name='queryContext'),
  requestId?: string(name='requestId', example='123456'),
  sceneItems?: [
    SceneItem
  ](name='sceneItems'),
  searchInformation?: SearchInformation(name='searchInformation'),
  weiboItems?: [
    WeiboItem
  ](name='weiboItems'),
}

model GlobalPageItem {
  link?: string(name='link', description='This parameter is required.', example='https://baijiahao.baidu.com/s?id=1787881554557805096'),
  snippet?: string(name='snippet', example='100km/h-0制动能力上，仅有33.3m，不黑不吹，单看这个，小米SU7确实表现不错。而续航方面，101kWh电池容量，实现CLTC续航800km，还有现5分钟补能220km，15分钟补能510km的800V高压平台。而在...'),
  title?: string(name='title', description='This parameter is required.', example='小米SU7售价22.99万元起 高管亲自辟谣：发布前不会有价格'),
}

model GlobalQueryContext {
  originalQuery?: {
    page?: string(name='page'),
    query?: string(name='query'),
    timeRange?: string(name='timeRange'),
  }(name='originalQuery'),
}

model GlobalSceneItem {
  detail?: string(name='detail'),
  type?: string(name='type'),
}

model GlobalSearchInformation {
  searchTime?: long(name='searchTime'),
  total?: long(name='total'),
}

model GlobalSearchResult {
  pageItems?: [
    GlobalPageItem
  ](name='pageItems'),
  queryContext?: GlobalQueryContext(name='queryContext'),
  requestId?: string(name='requestId', example='123456'),
  sceneItems?: [
    GlobalSceneItem
  ](name='sceneItems'),
  searchInformation?: GlobalSearchInformation(name='searchInformation'),
}

model IncludeImage {
  height?: int32(name='height', example='324'),
  imageLink?: string(name='imageLink', example='http://k.sinaimg.cn/n/sinakd20121/594/w2048h946/20240328/74cf-32c0d62e843df76567d760b4459d57c1.jpg/w700d1q75cms.jpg'),
  width?: int32(name='width', example='700'),
}

model QueryContext {
  originalQuery?: {
    industry?: string(name='industry'),
    page?: string(name='page'),
    query?: string(name='query'),
    timeRange?: string(name='timeRange'),
  }(name='originalQuery'),
  rewrite?: {
    enabled?: boolean(name='enabled'),
    timeRange?: string(name='timeRange'),
  }(name='rewrite'),
}

model RequestContents {
  mainText?: boolean(name='mainText'),
  markdownText?: boolean(name='markdownText'),
  rerankScore?: boolean(name='rerankScore'),
  summary?: boolean(name='summary'),
}

model SceneItem {
  detail?: string(name='detail'),
  type?: string(name='type'),
}

model ScorePageItem {
  cardType?: string(name='cardType', description='This parameter is required.', example='structure_web_info'),
  displayLink?: string(name='displayLink', description='This parameter is required.', example='baijiahao.baidu.com'),
  hostLogo?: string(name='hostLogo', example='https://s2.zimgs.cn/ims?kt=url&at=smstruct&key=aHR0cHM6Ly9ndy5hbGljZG4uY29tL0wxLzcyMy8xNTY1MjU2NjAwLzJhL2YwL2I0LzJhZjBiNDQxMGI5YmVlMDVjOGVlNGJmODk3MTNkNTFjLnBuZw==&sign=yx:CUlNNQVJQjFrk3Kxt2F3KWhTOFU=&tv=400_400'),
  hostname?: string(name='hostname', example='新华网'),
  htmlSnippet?: string(name='htmlSnippet', description='This parameter is required.', example='100km/h-0制动能力上，仅有33.3m，不黑不吹，单看这个，<em>小米SU7</em>确实表现不错。而续航方面，101kWh电池容量，实现CLTC续航800km，还有现5分钟补能220km，15分钟补能510km的800V高压平台。而在...'),
  htmlTitle?: string(name='htmlTitle', description='This parameter is required.', example='<em>小米</em>SU7售价22.99万元起 高管亲自辟谣：发布前不会有<em>价格</em>-百家号'),
  images?: [
    IncludeImage
  ](name='images'),
  link?: string(name='link', description='This parameter is required.', example='https://baijiahao.baidu.com/s?id=1787881554557805096'),
  mainText?: string(name='mainText', example='昨天	，	小米	汽车	没有	发布	，	但	相关	的	信息	透露	的	差	不	多	了	。		
		在	发布	会	现场	，	雷军	直接	称	小米	S	U	7	对	标	特斯拉	保时捷	，	有	100	项	行业	领先	，	可见	“	遥遥	领先	”	已经	不再	是	华为	专利	了	？		
	
		而	在	介绍	技术	时	，	雷军	也	从	电机	、	电池	、	大	压铸	、	自动	驾驶	、	智能	座舱	等	五	大	方面	展开	，	充分	展示	了	小米	汽车	的	技术	以及	技术	储备	，		 		能	堆	的	料	，	全都	堆	上去	了	…	…		
		大家	比较	感	兴趣	的	性能	方面	，	2	.	78	s	的	0	-	100	km	/	h	加速	，	265	km	/	h	的	最高	时速'),
  markdownText?: string(name='markdownText'),
  mime?: string(name='mime', example='text/html'),
  pageMap?: map[string]string(name='pageMap'),
  publishTime?: long(name='publishTime', description='This parameter is required.', example='1704426524000'),
  score?: double(name='score', example='0.234325235'),
  siteLabel?: string(name='siteLabel', example='权威媒体'),
  snippet?: string(name='snippet', example='100km/h-0制动能力上，仅有33.3m，不黑不吹，单看这个，小米SU7确实表现不错。而续航方面，101kWh电池容量，实现CLTC续航800km，还有现5分钟补能220km，15分钟补能510km的800V高压平台。而在...'),
  summary?: string(name='summary'),
  title?: string(name='title', description='This parameter is required.', example='小米SU7售价22.99万元起 高管亲自辟谣：发布前不会有价格'),
}

model SearchCredits {
  genericTextSearch?: int32(name='genericTextSearch'),
}

model SearchInformation {
  searchTime?: long(name='searchTime'),
  total?: long(name='total'),
}

model UnifiedCostCredits {
  search?: SearchCredits(name='search'),
  valueAdded?: ValueAddedCredits(name='valueAdded'),
}

model UnifiedOriginalQuery {
  query?: string(name='query'),
  timeRange?: string(name='timeRange'),
}

model UnifiedPageItem {
  hostLogo?: string(name='hostLogo'),
  hostname?: string(name='hostname'),
  images?: [ string ](name='images'),
  link?: string(name='link'),
  mainText?: string(name='mainText'),
  markdownText?: string(name='markdownText'),
  publishedTime?: string(name='publishedTime'),
  rerankScore?: double(name='rerankScore'),
  snippet?: string(name='snippet', example='2025-04-07T10:15:30.123+08:00'),
  summary?: string(name='summary'),
  title?: string(name='title'),
}

model UnifiedQueryContext {
  engineType?: string(name='engineType'),
  originalQuery?: UnifiedOriginalQuery(name='originalQuery'),
  rewrite?: UnifiedRewrite(name='rewrite'),
}

model UnifiedRewrite {
  enabled?: boolean(name='enabled'),
  timeRange?: string(name='timeRange'),
}

model UnifiedSceneItem {
  detail?: string(name='detail'),
  type?: string(name='type'),
}

model UnifiedSearchInformation {
  searchTime?: long(name='searchTime'),
}

model UnifiedSearchRequest {
  category?: string(name='category'),
  contents?: RequestContents(name='contents'),
  engineType?: string(name='engineType'),
  query?: string(name='query'),
  timeRange?: string(name='timeRange'),
}

model UnifiedSearchResponse {
  costCredits?: UnifiedCostCredits(name='costCredits'),
  pageItems?: [
    UnifiedPageItem
  ](name='pageItems'),
  queryContext?: UnifiedQueryContext(name='queryContext'),
  requestId?: string(name='requestId'),
  sceneItems?: [
    UnifiedSceneItem
  ](name='sceneItems'),
  searchInformation?: UnifiedSearchInformation(name='searchInformation'),
}

model ValueAddedCredits {
  advanced?: int32(name='advanced'),
  summary?: int32(name='summary'),
}

model WeiboItem {
  cardType?: string(name='cardType', description='This parameter is required.', example='weibo_strong'),
  homepageLink?: string(name='homepageLink', example='https://m.weibo.cn/u/7761793874?luicode=20000061&lfid=5024099350350075'),
  htmlSnippet?: string(name='htmlSnippet', description='This parameter is required.', example='【小调查：你会买<em>小米SU7</em>吗？】#小米SU7路测覆盖300多城市#4月17日，@小米汽车 发文称SU7道路测试覆盖全国300多个城市，涵盖极寒，极热天气，总里程数高达540万公里，目前仍在进行中。  网页链接'),
  images?: [ string ](name='images'),
  link?: string(name='link', description='This parameter is required.', example='https://m.weibo.cn/detail/5024099350350075?wm=90194_90009'),
  publishDisplayTime?: string(name='publishDisplayTime', description='This parameter is required.', example='1小时前'),
  username?: string(name='username', example='白鹿科技'),
}

model AiSearchRequest {
  industry?: string(name='industry', example='finance'),
  page?: int32(name='page', example='{\\\\"total_count\\\\": 6851, \\\\"page_number\\\\": 54, \\\\"page_size\\\\": 100}'),
  query?: string(name='query', description='This parameter is required.'),
  sessionId?: string(name='sessionId', example='17dc8bcd-f34a-46d1-a7a3-0fa3d1ce3824'),
  timeRange?: string(name='timeRange', example='OneWeek'),
}

model AiSearchResponseBody = {
  header?: {
    event?: string(name='event', example='on_common_search_end'),
    eventId?: string(name='eventId', example='988021f0-951a-43d0-ba4d-785359e7e7be'),
    queryContext?: {
      originalQuery?: {
        industry?: string(name='industry'),
        page?: int32(name='page'),
        query?: string(name='query'),
        timeRange?: string(name='timeRange'),
      }(name='originalQuery'),
      rewrite?: {
        enabled?: boolean(name='enabled'),
        timeRange?: string(name='timeRange'),
      }(name='rewrite'),
    }(name='queryContext'),
    responseTime?: long(name='responseTime', example='1293'),
  }(name='header'),
  payload?: string(name='payload', example='{"header":{"eventId":"6f617de0-204f-406f-a9be-34779c06d498","event":"on_common_search_start","responseTime":120},"payload":"","requestId":"715d01a0-de7e-42c3-abca-b901fcd79b39"}'),
  requestId?: string(name='requestId', description='Id of the request', example='ECB2144C-E277-5434-80E6-12D26678D364'),
}

model AiSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: AiSearchResponseBody(name='body'),
}

/**
 * @summary AI搜索流式接口
 *
 * @param request AiSearchRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return AiSearchResponse
 */
async function aiSearchWithOptions(request: AiSearchRequest, headers: map[string]string, runtime: Util.RuntimeOptions): AiSearchResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.industry)) {
    query['industry'] = request.industry;
  }
  if (!Util.isUnset(request.page)) {
    query['page'] = request.page;
  }
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.sessionId)) {
    query['sessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'AiSearch',
    version = '2024-11-11',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v3/linkedRetrieval/commands/aiSearch`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary AI搜索流式接口
 *
 * @param request AiSearchRequest
 * @return AiSearchResponse
 */
async function aiSearch(request: AiSearchRequest): AiSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return aiSearchWithOptions(request, headers, runtime);
}

model GenericAdvancedSearchRequest {
  industry?: string(name='industry'),
  query?: string(name='query', description='This parameter is required.'),
  sessionId?: string(name='sessionId', example='job-4065bee3-e7aa-49fc-aad2-a8e3a7fd6acd'),
  timeRange?: string(name='timeRange', example='OneWeek'),
}

model GenericAdvancedSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GenericSearchResult  
}

/**
 * @summary 增强版通用搜索
 *
 * @param request GenericAdvancedSearchRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GenericAdvancedSearchResponse
 */
async function genericAdvancedSearchWithOptions(request: GenericAdvancedSearchRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GenericAdvancedSearchResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.industry)) {
    query['industry'] = request.industry;
  }
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.sessionId)) {
    query['sessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GenericAdvancedSearch',
    version = '2024-11-11',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v2/linkedRetrieval/commands/genericAdvancedSearch`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 增强版通用搜索
 *
 * @param request GenericAdvancedSearchRequest
 * @return GenericAdvancedSearchResponse
 */
async function genericAdvancedSearch(request: GenericAdvancedSearchRequest): GenericAdvancedSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return genericAdvancedSearchWithOptions(request, headers, runtime);
}

model GenericSearchRequest {
  enableRerank?: boolean(name='enableRerank'),
  industry?: string(name='industry'),
  page?: int32(name='page', example='1'),
  query?: string(name='query', description='This parameter is required.'),
  returnMainText?: boolean(name='returnMainText'),
  returnMarkdownText?: boolean(name='returnMarkdownText'),
  returnSummary?: boolean(name='returnSummary'),
  sessionId?: string(name='sessionId'),
  timeRange?: string(name='timeRange', example='OneWeek'),
}

model GenericSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GenericSearchResult  
}

/**
 * @summary 通用搜索
 *
 * @param request GenericSearchRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GenericSearchResponse
 */
async function genericSearchWithOptions(request: GenericSearchRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GenericSearchResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.enableRerank)) {
    query['enableRerank'] = request.enableRerank;
  }
  if (!Util.isUnset(request.industry)) {
    query['industry'] = request.industry;
  }
  if (!Util.isUnset(request.page)) {
    query['page'] = request.page;
  }
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.returnMainText)) {
    query['returnMainText'] = request.returnMainText;
  }
  if (!Util.isUnset(request.returnMarkdownText)) {
    query['returnMarkdownText'] = request.returnMarkdownText;
  }
  if (!Util.isUnset(request.returnSummary)) {
    query['returnSummary'] = request.returnSummary;
  }
  if (!Util.isUnset(request.sessionId)) {
    query['sessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GenericSearch',
    version = '2024-11-11',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v2/linkedRetrieval/commands/genericSearch`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 通用搜索
 *
 * @param request GenericSearchRequest
 * @return GenericSearchResponse
 */
async function genericSearch(request: GenericSearchRequest): GenericSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return genericSearchWithOptions(request, headers, runtime);
}

model GlobalSearchRequest {
  page?: int32(name='page', example='1'),
  pageSize?: int32(name='pageSize', example='10'),
  query?: string(name='query', description='This parameter is required.'),
  timeRange?: string(name='timeRange', example='OneWeek'),
}

model GlobalSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GlobalSearchResult  
}

/**
 * @summary 通晓搜索-出海版(全球信息搜索)
 *
 * @param request GlobalSearchRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GlobalSearchResponse
 */
async function globalSearchWithOptions(request: GlobalSearchRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GlobalSearchResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.page)) {
    query['page'] = request.page;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['pageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GlobalSearch',
    version = '2024-11-11',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v1/iqs/search/global`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 通晓搜索-出海版(全球信息搜索)
 *
 * @param request GlobalSearchRequest
 * @return GlobalSearchResponse
 */
async function globalSearch(request: GlobalSearchRequest): GlobalSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return globalSearchWithOptions(request, headers, runtime);
}

